#pragma once
#include <vector>
#include "Character.h"
#include "Input.h"
#include "Sentence.h"
#include "TileAction.h"
using namespace std;

class TileAction;

struct MenuItem
{
	MenuItem(string aName)
	{
		name = aName;
		parent = nullptr;
		isOpen = true;
		action = ACTION_NONE;
		isEquipped = false;
	}

	MenuItem(string aName, MenuItem* aParent)
	{
		name = aName;
		parent = aParent;
		isOpen = false;
		action = ACTION_NONE;
		isEquipped = false;
	}

	~MenuItem()
	{
		for(unsigned int i=0; i<menus.size(); i++) delete menus[i];
	}

	MenuItem* AddMenu(string aName)
	{
		MenuItem* menu = new MenuItem(aName,this);
		menus.push_back(menu);
		return menu;
	}

	MenuItem* AddMenu(MenuItem* aMenu)
	{
		aMenu->parent = this;
		menus.push_back(aMenu);
		return aMenu;
	}

	string name; 
	vector<MenuItem*> menus;
	MenuItem* parent;
	bool isOpen;
	bool isEquipped;

	EMenuAction action;
};

class Menu
{
	public:
		Menu(Character* aHero);
		Menu(Character* aHero, Character* aCharacter);
		Menu(Character* aHero, TileAction* aTileAction);
		~Menu();

		void SetVisible(bool aVisible);
		bool GetVisible() { return isVisible;};

		void ProceedInput(Input* aInput);

		MenuItem* root;
		MenuItem* selected;

		MenuItem* clothes;
		MenuItem* inventory;
		MenuItem* buyInventory;
		MenuItem* purse;

		MenuItem* back;
		MenuItem* forceBack;

		Character* hero;
		int interlocutorFacing;
		Character* interlocutor;
		Phrase* phrase;
		TileAction* tileAction;

	private:
		unsigned int NumberInMenu(MenuItem* aMenu);
		void RefreshInventory();
		void RefreshClothes();
		void RefreshPurse();

		void Init();

		void PerformAction();

		bool isVisible;
};

